package exercise;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;

import javax.swing.filechooser.FileSystemView;

public class Ex5 {
	public static void main(String[] args) {
		File file1=new File("D:/iotest2/Stream.txt");
		File file2=new File("C:/Stream.txt");
		Writer wt=null;
		Reader rd=null;
		Writer wtt=null;
		try {
			wt=new FileWriter(file1);
			
			wt.write("I love you!");
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(wt!=null)
				try {
					wt.close();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		try {
			wtt=new FileWriter(file2);
			rd=new FileReader(file1);
			int n=0;
			while((n=rd.read())!=-1){
				p((char)n);
				wtt.write((char)n);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(wtt!=null)
				try {
					wtt.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
	}
    static void p(Object o){
    	System.out.print(o);
    }
}
